<template>
  <div class="medicineContent">
    <div class="medicineTitle">
      <div class="customerTitle">海川医药中药仓{{ systemTime }}日报</div>
      <el-button type="success" @click="saveZycdaily">保存</el-button>
    </div>
    <div class="customtr1">
      <div class="customText">客户/类别</div>
      <div class="customText">出库(条)</div>
      <div class="customText">拼箱数</div>
      <div class="customText">整箱数</div>
      <div class="customText">总金额</div>
      <div class="customText">异常单据</div>
      <div class="customText">作业开始时间</div>
      <div class="customText">作业结束时间</div>
      <!-- <div class="customText">立库件数</div>
      <div class="completeText">出库总件数</div> -->
    </div>
    <div class="customtr2">
      <div class="customText wyLayout">大洋</div>
      <div class="delivery">
        <div class="deliveryTop">
          <el-input
            @input="calculateckTotal"
            v-model="form.dyCk"
            size="medium"
          />
        </div>
      </div>
      <div class="customText">
        <el-input
          @input="calculatepxsTotal"
          v-model="form.dyPxs"
          size="medium"
        />
      </div>
      <div class="delivery">
        <div class="deliveryTop">
          <el-input
            v-model="form.dyZxs"
            @input="calculatezxsTotal"
            size="medium"
          />
        </div>
      </div>
      <div class="delivery">
        <div class="deliveryTop">
          <el-input
            @input="calculatezjeTotal"
            v-model="form.dyZje"
            size="medium"
          />
        </div>
      </div>
      <div class="delivery">
        <div class="deliveryTop">
          <el-input
            @input="calculateycdjTotal"
            v-model="form.dyYcdj"
            size="medium"
          />
        </div>
      </div>
      <div class="delivery">
        <div class="deliveryTop">
          <el-time-picker
            v-model="form.dyZyscs"
            placeholder=""
            value-format="HH:mm"
            format="HH:mm"
          >
          </el-time-picker>
        </div>
      </div>
      <div class="delivery">
        <div class="deliveryTop noborder">
          <el-time-picker
            v-model="form.dyZysce"
            placeholder=""
            value-format="HH:mm"
            format="HH:mm"
          >
          </el-time-picker>
        </div>
      </div>
    </div>
    <div class="customtr2">
      <div class="customText wyLayout">海通</div>
      <div class="delivery">
        <div class="deliveryTop">
          <el-input
            @input="calculateckTotal"
            v-model="form.htCk"
            size="medium"
          />
        </div>
      </div>
      <div class="customText">
        <el-input
          @input="calculatepxsTotal"
          v-model="form.htPxs"
          size="medium"
        />
      </div>
      <div class="delivery">
        <div class="deliveryTop">
          <el-input
            v-model="form.htZxs"
            @input="calculatezxsTotal"
            size="medium"
          />
        </div>
      </div>
      <div class="delivery">
        <div class="deliveryTop">
          <el-input
            @input="calculatezjeTotal"
            v-model="form.htZje"
            size="medium"
          />
        </div>
      </div>
      <div class="delivery">
        <div class="deliveryTop">
          <el-input
            @input="calculateycdjTotal"
            v-model="form.htYcdj"
            size="medium"
          />
        </div>
      </div>
      <div class="delivery">
        <div class="deliveryTop">
          <el-time-picker
            v-model="form.htZyscs"
            placeholder=""
            value-format="HH:mm"
            format="HH:mm"
          >
          </el-time-picker>
        </div>
      </div>
      <div class="delivery">
        <div class="deliveryTop noborder">
          <el-time-picker
            v-model="form.htZysce"
            placeholder=""
            value-format="HH:mm"
            format="HH:mm"
          >
          </el-time-picker>
        </div>
      </div>
    </div>
    <div class="customtr3">
      <div class="customText wyLayout">伟业</div>
      <div class="customText">
        <el-input @input="calculateckTotal" v-model="form.wyCk" size="medium" />
      </div>
      <div class="customText">
        <el-input
          @input="calculatepxsTotal"
          v-model="form.wyPxs"
          size="medium"
        />
      </div>
      <div class="customText">
        <el-input
          v-model="form.wyZxs"
          @input="calculatezxsTotal"
          size="medium"
        />
      </div>
      <div class="customText">
        <el-input
          @input="calculatezjeTotal"
          v-model="form.wyZje"
          size="medium"
        />
      </div>
      <div class="customText">
        <el-input
          @input="calculateycdjTotal"
          v-model="form.wyYcdj"
          size="medium"
        />
      </div>
      <div class="customText">
        <el-time-picker
          v-model="form.wyZyscs"
          placeholder=""
          value-format="HH:mm"
          format="HH:mm"
        >
        </el-time-picker>
      </div>
      <div class="completeText">
        <el-time-picker
          v-model="form.wyZysce"
          placeholder=""
          value-format="HH:mm"
          format="HH:mm"
        >
        </el-time-picker>
      </div>
    </div>
    <div class="customtr3">
      <div class="customText wyLayout">重药</div>
      <div class="customText">
        <el-input @input="calculateckTotal" v-model="form.cyCk" size="medium" />
      </div>
      <div class="customText">
        <el-input
          @input="calculatepxsTotal"
          v-model="form.cyPxs"
          size="medium"
        />
      </div>
      <div class="customText">
        <el-input
          v-model="form.cyZxs"
          @input="calculatezxsTotal"
          size="medium"
        />
      </div>
      <div class="customText">
        <el-input
          @input="calculatezjeTotal"
          v-model="form.cyZje"
          size="medium"
        />
      </div>
      <div class="customText">
        <el-input
          @input="calculateycdjTotal"
          v-model="form.cyYcdj"
          size="medium"
        />
      </div>
      <div class="customText">
        <el-time-picker
          v-model="form.cyZyscs"
          placeholder=""
          value-format="HH:mm"
          format="HH:mm"
        >
        </el-time-picker>
      </div>
      <div class="completeText">
        <el-time-picker
          v-model="form.cyZysce"
          placeholder=""
          value-format="HH:mm"
          format="HH:mm"
        >
        </el-time-picker>
      </div>
    </div>
    <div class="customtr3">
      <div class="customText wyLayout">其他货主</div>
      <div class="customText">
        <el-input @input="calculateckTotal" v-model="form.qtCk" size="medium" />
      </div>
      <div class="customText">
        <el-input
          @input="calculatepxsTotal"
          v-model="form.qtPxs"
          size="medium"
        />
      </div>
      <div class="customText">
        <el-input
          v-model="form.qtZxs"
          @input="calculatezxsTotal"
          size="medium"
        />
      </div>
      <div class="customText">
        <el-input
          @input="calculatezjeTotal"
          v-model="form.qtZje"
          size="medium"
        />
      </div>
      <div class="customText">
        <el-input
          @input="calculateycdjTotal"
          v-model="form.qtYcdj"
          size="medium"
        />
      </div>
      <div class="customText">
        <el-time-picker
          v-model="form.qtZyscs"
          placeholder=""
          value-format="HH:mm"
          format="HH:mm"
        >
        </el-time-picker>
      </div>
      <div class="completeText">
        <el-time-picker
          v-model="form.qtZysce"
          placeholder=""
          value-format="HH:mm"
          format="HH:mm"
        >
        </el-time-picker>
      </div>
    </div>
    <div class="customtr4">
      <div class="customText wyLayout">合计</div>
      <div class="customText">
        <el-input disabled v-model="ckTotal" size="medium" />
      </div>
      <div class="customText">
        <el-input disabled v-model="pxsTotal" size="medium" />
      </div>
      <div class="customText">
        <el-input disabled v-model="zxsTotal" size="medium" />
      </div>
      <div class="customText">
        <el-input disabled v-model="zjeTotal" size="medium" />
      </div>
      <div class="customText">
        <el-input disabled v-model="ycdjTotal" size="medium" />
      </div>
      <div class="customText"></div>
      <div class="completeText">
        <!-- <el-select v-model="form.dyZyscs" clearable placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select> -->
      </div>
    </div>
  </div>
</template>

<script>
import { dailyaddzyc, dailylistzyc } from "@/api/system/daily";
export default {
  data() {
    return {
      //   options: [
      //     { value: "up", label: "\u2191" },
      //     { value: "down", label: "\u2193" },
      //   ],
      soldoutTime: new Date().toISOString().split("T")[0],
      // 陕西海通零货条目数
      ids: null,
      systemTime: "",
      ckTotal: undefined,
      pxsTotal: undefined,
      zxsTotal: undefined,
      zjeTotal: undefined,
      ycdjTotal: undefined,
      // 伟业
      form: {
        rbSj: new Date().toISOString().split("T")[0],
        // 大洋
        dyCk: null,
        dyPxs: null,
        dyZxs: null,
        dyZje: null,
        dyYcdj: null,
        dyZyscs: null,
        dyZysce: null,
        // 海通
        htCk: null,
        htPxs: null,
        htZxs: null,
        htZje: null,
        htYcdj: null,
        htZyscs: null,
        htZysce: null,
        // 伟业
        wyCk: null,
        wyPxs: null,
        wyZxs: null,
        wyZje: null,
        wyYcdj: null,
        wyZyscs: null,
        wyZysce: null,
        // 重药
        cyCk: null,
        cyPxs: null,
        cyZxs: null,
        cyZje: null,
        cyYcdj: null,
        cyZyscs: null,
        cyZysce: null,
        // 其他
        qtCk: null,
        qtPxs: null,
        qtZxs: null,
        qtZje: null,
        qtYcdj: null,
        qtZyscs: null,
        qtZysce: null,
      },
    };
  },
  mounted() {
    // 创建一个 Date 对象
    const currentDate = new Date();
    // 获取当前年份
    const year = currentDate.getFullYear();
    // 获取当前月份（注意：月份是从 0 开始计数的，所以需要加 1）
    const month = currentDate.getMonth() + 1;
    // 获取当前日期
    const day = currentDate.getDate();
    // 打印年月日
    this.systemTime = `${year}年${month}月${day}日`;
    this.getzyclist();
  },
  beforeDestroy() {},
  methods: {
    // 保存
    saveZycdaily() {
      dailyaddzyc(this.form).then((res) => {
        console.log(res);
        this.$modal.msgSuccess("新增成功");
        this.getzyclist();
      });
    },
    getzyclist() {
      dailylistzyc().then((res) => {
        if (res.data) {
          this.form = res.data;
          this.ckTotal =
            Number(this.form.dyCk) +
            Number(this.form.htCk) +
            Number(this.form.wyCk) +
            Number(this.form.cyCk) +
            Number(this.form.qtCk);
          this.pxsTotal =
            Number(this.form.dyPxs) +
            Number(this.form.htPxs) +
            Number(this.form.wyPxs) +
            Number(this.form.cyPxs) +
            Number(this.form.qtPxs);
          this.zxsTotal =
            Number(this.form.dyZxs) +
            Number(this.form.htZxs) +
            Number(this.form.wyZxs) +
            Number(this.form.cyZxs) +
            Number(this.form.qtZxs);
          this.zjeTotal = this.addDecimals(
            Number(this.form.dyZje),
            Number(this.form.htZje),
            Number(this.form.wyZje),
            Number(this.form.cyZje),
            Number(this.form.qtZje)
          );
          this.ycdjTotal =
            Number(this.form.dyYcdj) +
            Number(this.form.htYcdj) +
            Number(this.form.wyYcdj) +
            Number(this.form.cyYcdj) +
            Number(this.form.qtYcdj);
        }
      });
    },
    addDecimals(...nums) {
      const precision = 1000000; // 保留六位小数
      const sum = nums.reduce(
        (acc, num) => acc + Math.round(num * precision),
        0
      );
      return sum / precision;
    },
    calculateckTotal() {
      this.ckTotal =
        Number(this.form.dyCk) +
        Number(this.form.htCk) +
        Number(this.form.wyCk) +
        Number(this.form.cyCk) +
        Number(this.form.qtCk);
    },
    calculatepxsTotal() {
      this.pxsTotal =
        Number(this.form.dyPxs) +
        Number(this.form.htPxs) +
        Number(this.form.wyPxs) +
        Number(this.form.cyPxs) +
        Number(this.form.qtPxs);
    },
    calculatezxsTotal() {
      this.zxsTotal =
        Number(this.form.dyZxs) +
        Number(this.form.htZxs) +
        Number(this.form.wyZxs) +
        Number(this.form.cyZxs) +
        Number(this.form.qtZxs);
    },
    calculatezjeTotal() {
      this.zjeTotal = this.addDecimals(
        Number(this.form.dyZje),
        Number(this.form.htZje),
        Number(this.form.wyZje),
        Number(this.form.cyZje),
        Number(this.form.qtZje)
      );
    },
    calculateycdjTotal() {
      this.ycdjTotal =
        Number(this.form.dyYcdj) +
        Number(this.form.htYcdj) +
        Number(this.form.wyYcdj) +
        Number(this.form.cyYcdj) +
        Number(this.form.qtYcdj);
    },
  },
};
</script>

<style lang="scss" scoped>
.medicineContent {
  width: 100%;
  height: 100%;
  ::v-deep .el-table__body-wrapper {
    border: 1px solid #181616;
  }
  .el-table--group::after,
  .el-table--border::after {
    background-color: #181616;
  }
  ::v-deep .el-table--enable-row-hover .el-table__body tr:hover > td {
    background-color: transparent;
  }
  ::v-deep .el-input__inner {
    height: 65px;
    line-height: 65px;
    border: none;
    text-align: center;
    color: #000000;
    width: 100%;
  }
  ::v-deep .el-date-editor.el-input,
  .el-date-editor.el-input__inner {
    width: 100%;
  }
  ::v-deep .el-input--prefix .el-input__inner {
    border: none;
  }
  ::v-deep .el-table tr {
    height: 70px;
  }
  .medicineTitle {
    display: flex;
    align-items: center;
    .customerTitle {
      width: 100%;
      font-size: 24px;
      font-weight: 700;
      margin: 30px 0 40px 0;
    }
    ::v-deep .el-button--success {
      height: 36px;
    }
  }
  .customtr1 {
    width: 100%;
    height: 70px;
    border: 1px solid #e7dfdf;
    background: #05a5ff;
    display: flex;
    font-size: 16px;
    font-weight: 700;
    color: #ffffff;
    justify-content: space-around;
    .customText {
      width: 12.5%;
      height: 70px;
      line-height: 70px;
      text-align: center;
      border-right: 1px solid #e7dfdf;
    }
    .completeText {
      width: 10%;
      height: 70px;
      line-height: 70px;
      text-align: center;
    }
  }
  .customtr2 {
    width: 100%;
    height: 70px;
    border-bottom: 1px solid #181616;
    border-left: 1px solid #181616;
    border-right: 1px solid #181616;
    // background: #00d9ff;
    display: flex;
    justify-content: space-around;
    .customText {
      width: 12.5%;
      height: 70px;
      line-height: 70px;
      text-align: center;
      border-right: 1px solid #181616;
    }
    .wyLayout {
      font-weight: 700;
    }
    .delivery {
      width: 12.5%;
      display: flex;
      flex-direction: column;
      //   border-right: 1px solid #181616;
      .deliveryTop {
        height: 100%;
        line-height: 70px;
        border-right: 1px solid #181616;
      }
      .noborder {
        border-right: none !important;
      }
    }
  }
  .customtr3 {
    width: 100%;
    height: 70px;
    border-bottom: 1px solid #181616;
    border-left: 1px solid #181616;
    border-right: 1px solid #181616;
    // background: #00d9ff;
    display: flex;
    justify-content: space-around;
    .customText {
      width: 12.5%;
      height: 70px;
      line-height: 70px;
      text-align: center;
      border-right: 1px solid #181616;
    }
    .wyLayout {
      font-weight: 700;
    }
    .completeText {
      width: 12.5%;
      height: 70px;
      line-height: 70px;
      text-align: center;
    }
  }
  .customtr4 {
    width: 100%;
    height: 70px;
    border-bottom: 1px solid #181616;
    border-left: 1px solid #181616;
    border-right: 1px solid #181616;
    background: #75d561;
    display: flex;
    justify-content: space-around;
    ::v-deep .el-input.is-disabled .el-input__inner {
      background: #75d561;
      font-weight: 700;
      color: #ff4800;
      font-size: 18px;
    }
    .customText {
      width: 12.5%;
      height: 70px;
      line-height: 70px;
      text-align: center;
      border-right: 1px solid #181616;
    }
    // .totalText {
    //   width: 11.1%;
    // }
    .bhxsbg {
      background: #f5f7fa;
      border-bottom: 1px solid #181616;
    }
    .wyLayout {
      font-weight: 700;
    }
    .completeText {
      background: #75d561;
      width: 12.5%;
      height: 70px;
      line-height: 70px;
      text-align: center;
      border-bottom: 1px solid #181616;
    }
  }
}
</style>